<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script>
    //定义异步路由
    let allAsyncRoute = [
        {
            name: 'Acl',
            children: [
                { name: 'role' },
                { name: 'auth' }
            ]
        },
        {
            name: 'Product',
            children: [
                { name: 'Trademark' },
                { name: 'Attr' },
                { name: 'Sku' },
                { name: 'Spu' }
            ]
        },
    ]

    let routes = ["Product",'Sku'];
    //递归练习
    function findAsyncRoute(allAsyncRoute, routes) {
        //规律一级路由
        return allAsyncRoute.filter(item => {
            //判断一级路由名字在routes数组里面是否出现，如果出现过滤出来
            if (routes.includes(item.name)) {
                //过滤二、三、四级、五级...有没有子路由过滤出来
                if (item.children && item.children.length > 0) {
                    item.children = findAsyncRoute(item.children, routes);
                }
                return true;
            }
        })
    }
    //最终想要过滤出来的异步路由：用户想要动态添加路由！！！！

    //zhangjie1
    let result = findAsyncRoute(JSON.parse(JSON.stringify(allAsyncRoute)), routes);
   
    //超管在登录
    console.log(allAsyncRoute);
</script>